package com.zzjc.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.zzjc.core.page.PageInterceptor;

import java.io.File;


@Configuration
@Component
public class WebConfig extends WebMvcConfigurerAdapter {

    @Autowired
    private GlobalConfig globalConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(new PageInterceptor());
        System.out.println("===========   拦截器注册完毕   ===========");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            registry.addResourceHandler("/swimmingFile/**").addResourceLocations("file:" + "D:\\swimmingFile" + File.separator);
        } else {
            registry.addResourceHandler("/swimmingFile/**").addResourceLocations("file:" + "/home/zzjc/swimmingFiles" + File.separator);
        }
    }
}
